/*
 * Vision_Sensor.h
 *
 *  Created on: Mar 21, 2024
 *      Author: 86177
 */

#ifndef PERIPHERALS_INC_CAMERA_H_
#define PERIPHERALS_INC_CAMERA_H_

#include <nvic.h>

#define CAM_SCL_L 		 	HAL_GPIO_WritePin(I2C_SCL_CH1_GPIO_Port, I2C_SCL_CH1_Pin, GPIO_PIN_RESET)
#define CAM_SCL_H 		 	HAL_GPIO_WritePin(I2C_SCL_CH1_GPIO_Port, I2C_SCL_CH1_Pin, GPIO_PIN_SET)

#define CAM_SDA_L 		 	HAL_GPIO_WritePin(I2C_SDA_CH1_GPIO_Port, I2C_SDA_CH1_Pin, GPIO_PIN_RESET)
#define CAM_SDA_H 		 	HAL_GPIO_WritePin(I2C_SDA_CH1_GPIO_Port, I2C_SDA_CH1_Pin, GPIO_PIN_SET)

#define CAM_DEFAULT_I2C_ADDRESS       	(0x32)
#pragma pack(1)
#define false 0
#define true 1
#define CAM_TARGET_RED 					1
#define CAM_TARGET_GREEN 				2
#define CAM_TARGET_BLUE 				3

struct QRdata
{
	int data1;
	int data2;
};

struct WonderCamQrCodeResultSumm {
  uint8_t current;
  uint8_t id;
  uint8_t __1[14];
  int16_t points[4][2];
  uint16_t len;
  uint8_t __2[14];
};

struct WonderCamFaceDetectResult {
  int16_t x;
  int16_t y;
  uint16_t w;
  uint16_t h;
} __attribute__((aligned(16)));

struct WonderCamObjDetectResult {
  int16_t x;
  int16_t y;
  uint16_t w;
  uint16_t h;
} __attribute__((aligned(16)));

struct WonderCamColorDetectResult {
  int16_t x;
  int16_t y;
  uint16_t w;
  uint16_t h;
} __attribute__((aligned(16)));

struct WonderCamLineResult {
  int16_t start_x;
  int16_t start_y;
  int16_t end_x;
  int16_t end_y;
  int16_t angle;
  int16_t offset;
} __attribute__((aligned(16)));

struct WonderCamAprilTagResult {
  int16_t x;
  int16_t y;
  uint16_t w;
  uint16_t h;
  float x_t;
  float x_r;
  float y_t;
  float y_r;
  float z_t;
  float z_r;
} __attribute__((aligned(32)));

#pragma pack()

#define WONDERCAM_LED_ON           (true)
#define WONDERCAM_LED_OFF          (false)

typedef enum {
  APPLICATION_NONE = 0,
  APPLICATION_FACEDETECT,
  APPLICATION_OBJDETECT,
  APPLICATION_CLASSIFICATION,
  APPLICATION_FEATURELEARNING,
  APPLICATION_COLORDETECT,
  APPLICATION_LINEFOLLOW,
  APPLICATION_APRILTAG,
  APPLICATION_QRCODE,
  APPLICATION_BARCODE,
  APPLICATION_MAX,
} APPLICATION;

typedef enum {
  Aeroplane = 1,
  Bicycle,
  Bird,
  Boat,
  Bottle,
  Bus,
  Car,
  Cat,
  Chair,
  Cow,
  Diningtable,
  Dog,
  Horse,
  Motorbike,
  Person,
  Pottedplant,
  Sheep,
  Sofa,
  Train,
  Monitor
}Objects;

void camera_timer(void);

bool camera_set_target(uint8_t target);
bool camera_set_func(uint8_t func);

void camera_init(void);
void camera_deinit(void);
void camera_polling(void);

#endif /* PERIPHERALS_INC_CAMERA_H_ */
